﻿using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RK.WebApi.Ronma
{
    [Description("润马:webapi相关处理,成功后的自定义返回值"), HotUpdate]
    public class WebApiOperation : AbstractDynamicFormPlugIn
    {
        public override void OnAfterWebApiOperation(AfterWebApiOperationArgs e)
        {
            base.OnAfterWebApiOperation(e);
            if (e.WebContext.OperationResult.SuccessDataEnity.IsNullOrEmptyOrWhiteSpace())
            {
                return;
            }
            ArrayList arrayList = new ArrayList();
            JSONObject val = JSONObject.Parse(e.WebContext.RequestDTO.ToString());
            JSONObject jSONObject = val.GetJSONObject("CustomParams");
            Dictionary<string, object> dictionary = new Dictionary<string, object>(jSONObject);
            if (dictionary.ContainsKey("MESParamters"))
            {
                string text = string.Empty;
                string empty = string.Empty;
                List<DynamicObject> list = e.WebContext.OperationResult.SuccessDataEnity as List<DynamicObject>;
                foreach (DynamicObject item in list)
                {
                    if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "STK_InStock"))
                    {
                        text = "InStockEntry";
                        empty = "FLot";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "PUR_MRB"))
                    {
                        text = "PUR_MRBENTRY";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "PRD_MORPT"))
                    {
                        text = "PRD_MORPTENTRY";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "PRD_INSTOCK"))
                    {
                        text = "Entity";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "SAL_OUTSTOCK"))
                    {
                        text = "SAL_OUTSTOCKENTRY";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "SAL_RETURNSTOCK"))
                    {
                        text = "SAL_RETURNSTOCKENTRY";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "PRD_PickMtrl"))
                    {
                        text = "Entity";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "PRD_ReturnMtrl"))
                    {
                        text = "Entity";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "PRD_FeedMtrl"))
                    {
                        text = "Entity";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "PUR_MRB"))
                    {
                        text = "PUR_MRBENTRY";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "STK_OEMInStock"))
                    {
                        text = "OEMInStockEntry";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "STK_TransferDirect"))
                    {
                        text = "TransferDirectEntry";
                    }
                    else if (StringUtils.EqualsIgnoreCase(item["FFormId"].ToString(), "STK_MisDelivery"))
                    {
                        text = "BillEntry";
                    }
                    DynamicObjectCollection val2 = item[text] as DynamicObjectCollection;
                    foreach (DynamicObject item2 in val2)
                    {
                        Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
                        if (DynamicObjectUtils.Contains(item2, "F_LOTWMS"))
                        {
                            dictionary2.Add("WMSLOT", item2["F_LOTWMS"].ToString());
                            dictionary2.Add("ERPLOT", item2["Lot_Text"].ToString());
                        }
                        arrayList.Add(dictionary2);
                    }
                }
                Dictionary<string, object> dictionary3 = (Dictionary<string, object>)e.WebContext.ResponseDTO;
                dictionary3.Add("MESParamters", arrayList);
            }
        }
    }
}
